import cloudAdapter from "@/cloudAdapter/index.js";
import { ErrorLogger } from "./Logger";
const stateTree = {
    state: () => ({
        user: {
            info: null,
        },
    }),
    mutations: {
        changeUserInfo(state, info) {
            console.info("用户状态改变", info);
            state.user.info = info?.user;
            window.UserInfo = info?.user;
        },
    },
    actions: {
        SignOut() {
            return cloudAdapter.SignOut();
        },
        async SignIn(_, { type = "email", username, password }) {
            console.info("登录申请");
            const result = await cloudAdapter
                .SignIn({
                    type,
                    username,
                    password,
                })
                .catch(ErrorLogger);
            console.info("登录成功", result);
            return result;
        },
        async SignUp(_, { type = "email", username, password }) {
            console.log("注册申请");
            const result = await cloudAdapter
                .SignUp({
                    type,
                    username,
                    password,
                })
                .catch(ErrorLogger);
            console.log("注册成功", result);
            return result;
        },
        async Reset(_, username) {
            return cloudAdapter.Reset(username).catch(ErrorLogger);
        },
    },
};

export default stateTree;
